package 二叉树相关问题.BST;


//538
public class 把二叉搜索树转换为累加树 {
    public TreeNode convertBST(TreeNode root) {
        return traverse(root);
    }
    int sum=0;
    private TreeNode traverse(TreeNode root) {
        if (root==null)
            return null;
        traverse(root.right);
        sum+=root.val;
        root.val=sum;
        traverse(root.left);
        return root;
    }
}
